package com.entity;

public class User {
	
	private String code;
	private int cash;
	
	public User(String code,int cash) {
		this.code=code;
		this.cash=cash;
	}
	
	public void setCode(String code) {
		this.code = code;
	}
	
	public String getCode() {
		return code;
	}
	
	//存取款操作，本方法为同步方法
	public synchronized void oper(int x){
		try {
			Thread.sleep(1000);
			this.cash+=x;
			System.out.println(Thread.currentThread().getName()+"运行结束，增加\""+x+"\",当前用户账户余额为："+cash);
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public String toString() {
		return "User [code=" + code + ", cash=" + cash + "]";
	}
	
}
